﻿<phone:PhoneApplicationPage
    x:Class="Omnia.Wallet.Views.TransactionEditView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:Converters="clr-namespace:Omnia.Converters;assembly=Omnia.Converters"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:UX="clr-namespace:Omnia.UX;assembly=Omnia.UX"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewmodels="clr-namespace:Omnia.ViewModels;assembly=Omnia.ViewModels"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="False" d:DesignHeight="800" d:DesignWidth="480">

    <phone:PhoneApplicationPage.Resources>
    	<Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Converters:EnumTranslateConverter x:Key="EnumTranslateConverter"/>
        <Converters:ResourceKeyToPathdataConverter x:Key="ResourceKeyToPathdataConverter"/>
    </phone:PhoneApplicationPage.Resources>
    
    <Grid x:Name="LayoutRoot">
        <Grid.DataContext>
            <viewmodels:TransactionEditViewModel/>
        </Grid.DataContext>
        <Grid.Background>
            <ImageBrush Stretch="Fill" ImageSource="{Binding BackgroundImageSource, Mode=OneWay}"/>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel Grid.Row="0" Margin="12,17,0,12">
            <TextBlock Text="{StaticResource IDS_PAGE_TITLE}" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock Text="{StaticResource IDS_PAGE_HEADER_UPDATE_TRANSACTION}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <ScrollViewer>
                <StackPanel>
                    <TextBlock Style="{StaticResource PhoneTextSubtleStyle}" Text="{StaticResource IDS_LABEL_TRANS_AMOUNT}"/>
                    <TextBox InputScope="Number" Text="{Binding CurrentEditTransactionItem.Amount, Mode=TwoWay}"/>
                    <ListBox Grid.Column="1" VerticalAlignment="Center" Margin="12" ItemsSource="{Binding TransactionKinds}" SelectedItem="{Binding CurrentEditTransactionItem.Kind, Mode=TwoWay}" SelectionChanged="ListPicker_SelectionChanged">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ListBoxItem">
                                            <UX:UXRadioButton IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected, Mode=TwoWay}">
                                                <TextBlock Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding Converter={StaticResource EnumTranslateConverter}}"/>
                                            </UX:UXRadioButton>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ListBox.ItemContainerStyle>
                    </ListBox>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>

                        <toolkit:DatePicker Header="{StaticResource IDS_LABEL_TRANS_DATE}" Value="{Binding CurrentEditTransactionItem.Time, Mode=TwoWay}"/>
                        <toolkit:TimePicker Grid.Column="1" Header="{StaticResource IDS_LABEL_TRANS_TIME}" Value="{Binding CurrentEditTransactionItem.Time, Mode=TwoWay}"/>
                    </Grid>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>

                        <toolkit:ListPicker ItemsSource="{Binding ShowCategories}" 
                                            Header="{StaticResource IDS_LABEL_TRANS_CATEGORY}" 
                                            SelectedItem="{Binding SelectedCategoty, Mode=TwoWay}">
                            <toolkit:ListPicker.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="auto"/>
                                            <ColumnDefinition />
                                        </Grid.ColumnDefinitions>
                                        <Path Data="{Binding IconResourceKey, Converter={StaticResource ResourceKeyToPathdataConverter}}" 
                                              Stretch="Uniform" 
                                              Fill="#FF818181" 
                                              Width="20" Height="20" Margin="0,0,0,0" 
                                              RenderTransformOrigin="0.5,0.5">
                                            <Path.RenderTransform>
                                                <TransformGroup>
                                                    <RotateTransform Angle="0" />
                                                    <ScaleTransform ScaleX="1" ScaleY="1" />
                                                </TransformGroup>
                                            </Path.RenderTransform>
                                        </Path>
                                        <TextBlock Text="{Binding Name}" Margin="12,0" Grid.Column="1"/>
                                    </Grid>

                                </DataTemplate>
                            </toolkit:ListPicker.ItemTemplate>
                            <toolkit:ListPicker.FullModeItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="12,6">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="auto"/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <Path Data="{Binding IconResourceKey, Converter={StaticResource ResourceKeyToPathdataConverter}}" Fill="#FF818181" Height="20" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5" Stretch="Uniform" Width="20">
                                            <Path.RenderTransform>
                                                <TransformGroup>
                                                    <RotateTransform Angle="0"/>
                                                    <ScaleTransform ScaleY="1" ScaleX="1"/>
                                                </TransformGroup>
                                            </Path.RenderTransform>
                                        </Path>
                                        <TextBlock Grid.Column="1" Margin="12,0" Style="{StaticResource PhoneTextTitle3Style}" Text="{Binding Name}"/>
                                    </Grid>
                                </DataTemplate>
                            </toolkit:ListPicker.FullModeItemTemplate>
                        </toolkit:ListPicker>
                        <toolkit:ListPicker Grid.Column="1" 
                                            ItemsSource="{Binding PaymentWays, Mode=OneWay}" 
                                            Header="{StaticResource IDS_LABEL_TRANS_PAYMENTWAY}" 
                                            SelectedItem="{Binding CurrentEditTransactionItem.Paymentway, Mode=TwoWay}">
                            <toolkit:ListPicker.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Converter={StaticResource EnumTranslateConverter}}"/>
                                </DataTemplate>
                            </toolkit:ListPicker.ItemTemplate>
                        </toolkit:ListPicker>
                    </Grid>
                    <TextBlock Text="{StaticResource IDS_LABEL_TRANS_PLACE}" Style="{StaticResource PhoneTextSubtleStyle}"/>
                    <toolkit:AutoCompleteBox ItemsSource="{Binding StorePlaceCollection}" Text="{Binding CurrentEditTransactionItem.Place, Mode=TwoWay}" FilterMode="Contains" ValueMemberPath="Place">
                        <toolkit:AutoCompleteBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Place}" />
                            </DataTemplate>
                        </toolkit:AutoCompleteBox.ItemTemplate>
                    </toolkit:AutoCompleteBox>
                    <TextBlock Text="{StaticResource IDS_LABEL_TRANS_REMARK}" Style="{StaticResource PhoneTextSubtleStyle}"/>
                    <TextBox Text="{Binding CurrentEditTransactionItem.Remark, Mode=TwoWay}" AcceptsReturn="True" TextWrapping="Wrap"/>
                    <CheckBox Content="{StaticResource IDS_LABEL_TRANS_LINKTOCASE}" IsChecked="{Binding LinkToCase, Mode=TwoWay}"/>
                    <toolkit:AutoCompleteBox IsEnabled="{Binding LinkToCase}" 
                                                     ItemsSource="{Binding CasesCollection, Mode=OneWay}" 
                                                     ValueMemberPath="Title" 
                                                     SelectedItem="{Binding SelectedCase, Mode=TwoWay}" 
                                                     Visibility="{Binding LinkToCase, Converter={StaticResource BooleanToVisibilityConverter}}"
                                                     FilterMode="Contains" >
                        <toolkit:AutoCompleteBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Title}"/>
                            </DataTemplate>
                        </toolkit:AutoCompleteBox.ItemTemplate>
                    </toolkit:AutoCompleteBox>
                </StackPanel>
            </ScrollViewer>

            <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right">
                <UX:UXPathButton Margin="12" 
                                     Command="{Binding UpdateCommand}"
                                     IconPath="{StaticResource PATH_ICON_SUBMIT}"
                                     Padding="11"/>
                
                <UX:UXPathButton Margin="12" 
                                 IconPath="{StaticResource PATH_ICON_PREVIOUS}"
                                 Uri="/Views/TransactionsView.xaml"/>
            </StackPanel>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>